package org.domain.seam1.form;

import javax.ejb.Remove;
import javax.ejb.Stateful;

import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Logger;
import org.jboss.seam.log.Log;
import org.jboss.seam.faces.Renderer;
import org.jboss.seam.international.StatusMessage;
import org.jboss.seam.international.StatusMessages;
import org.hibernate.validator.Email;
import org.hibernate.validator.Length;
import org.hibernate.validator.NotNull;

@Name("SendMail")
public class SendMailBean {

	@NotNull
	private String fromName;
	@NotNull
	@Email
	private String fromAddress;
	@NotNull
	@Email
	private String replyToAddress;
	@NotNull
	private String toName;
	@NotNull
	@Email
	private String toAddress;
	@NotNull
	private String subject;
	@NotNull
	private String body;

	@Logger
	private Log log;

	@In
	StatusMessages statusMessages;

	@In
	private Renderer renderer;

	public void send() {
		// implement your business logic here
		log.info("SendMail.send() action called.");
		statusMessages.add("send email to #{SendMail.toAddress}.");
		try {
			renderer.render("/mailtemplates/mailTemplate.xhtml");
			statusMessages.add("Email sent successfully");
			log.info("Email sent successfully");
		} catch (Exception e) {
			statusMessages.add(StatusMessage.Severity.ERROR,
					"Email sending failed: " + e.getMessage());
			log.error("Email sending failed.");
			e.printStackTrace();
		}
	}

	public void setFromName(String fromName) {
		this.fromName = fromName;
	}

	public String getFromName() {
		return fromName;
	}

	public void setFromAddress(String fromAddress) {
		this.fromAddress = fromAddress;
	}

	public String getFromAddress() {
		return fromAddress;
	}

	public void setReplyToAddress(String replyToAddress) {
		this.replyToAddress = replyToAddress;
	}

	public String getReplyToAddress() {
		return replyToAddress;
	}

	public void setToName(String toName) {
		this.toName = toName;
	}

	public String getToName() {
		return toName;
	}

	public void setToAddress(String toAddress) {
		this.toAddress = toAddress;
	}

	public String getToAddress() {
		return toAddress;
	}

	public void setSubject(String subject) {
		this.subject = subject;
	}

	public String getSubject() {
		return subject;
	}

	public void setBody(String body) {
		this.body = body;
	}

	public String getBody() {
		return body;
	}

	// add additional action methods

}
